
package net.mcreator.playerhuds.client.gui;

import org.checkerframework.checker.units.qual.h;

import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.api.distmarker.Dist;

import net.minecraft.world.level.Level;
import net.minecraft.world.entity.player.Player;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.Minecraft;

import net.mcreator.playerhuds.procedures.MainHudHideAndShowProcedure;
import net.mcreator.playerhuds.procedures.GoldHeartHideAndShowProcedure;
import net.mcreator.playerhuds.procedures.ArmorHideAndShowProcedure;
import net.mcreator.playerhuds.procedures.AirHideAndShowProcedure;

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.platform.GlStateManager;

@Mod.EventBusSubscriber({Dist.CLIENT})
public class MainHudOverlay {
	@SubscribeEvent(priority = EventPriority.HIGHEST)
	public static void eventHandler(RenderGameOverlayEvent.Pre event) {
		if (event.getType() == RenderGameOverlayEvent.ElementType.ALL) {
			int w = event.getWindow().getGuiScaledWidth();
			int h = event.getWindow().getGuiScaledHeight();
			int posX = w / 2;
			int posY = h / 2;
			Level _world = null;
			double _x = 0;
			double _y = 0;
			double _z = 0;
			Player entity = Minecraft.getInstance().player;
			if (entity != null) {
				_world = entity.level;
				_x = entity.getX();
				_y = entity.getY();
				_z = entity.getZ();
			}
			Level world = _world;
			double x = _x;
			double y = _y;
			double z = _z;
			RenderSystem.disableDepthTest();
			RenderSystem.depthMask(false);
			RenderSystem.enableBlend();
			RenderSystem.setShader(GameRenderer::getPositionTexShader);
			RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA,
					GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
			RenderSystem.setShaderColor(1, 1, 1, 1);
			if (MainHudHideAndShowProcedure.execute(entity)) {
				RenderSystem.setShaderTexture(0, new ResourceLocation("playerhuds:textures/hud_strip_bg.png"));
				Minecraft.getInstance().gui.blit(event.getMatrixStack(), posX - 91, h - 39, 0, 0, 81, 9, 81, 9);

				RenderSystem.setShaderTexture(0, new ResourceLocation("playerhuds:textures/health_strip.png"));
				Minecraft.getInstance().gui.blit(event.getMatrixStack(), posX - 90, h - 38, 0, 0, (int)(entity.getPersistentData().getDouble("HealthStripUpdate")), 7, 79, 7);

				Minecraft.getInstance().font.draw(event.getMatrixStack(), "" + (entity.getPersistentData().getString("HealthNumShow")) + "",
						posX - 65 , h - 38, -1);
				if (GoldHeartHideAndShowProcedure.execute(entity)) {
					RenderSystem.setShaderTexture(0, new ResourceLocation("playerhuds:textures/gold_heart.png"));
					Minecraft.getInstance().gui.blit(event.getMatrixStack(), posX - 100, h - 39, 0, 0, 9, 9, 9, 9);
				}
				if (GoldHeartHideAndShowProcedure.execute(entity))
					Minecraft.getInstance().font.draw(event.getMatrixStack(), "" + (entity.getPersistentData().getString("GoldHeartNumShow")) + "",
							posX - 106 - (int)(entity.getPersistentData().getDouble("GoldHeartMoveUpdate")) , h - 38, -26368);
				if (ArmorHideAndShowProcedure.execute(entity)) {
					RenderSystem.setShaderTexture(0, new ResourceLocation("playerhuds:textures/hud_strip_bg.png"));
					Minecraft.getInstance().gui.blit(event.getMatrixStack(), posX - 91, h - 49, 0, 0, 81, 9, 81, 9);
				}
				if (ArmorHideAndShowProcedure.execute(entity)) {
					RenderSystem.setShaderTexture(0, new ResourceLocation("playerhuds:textures/armor_strip.png"));
					Minecraft.getInstance().gui.blit(event.getMatrixStack(), posX - 90, h - 48, 0, 0, (int)(entity.getPersistentData().getDouble("ArmorStripUpdate")), 7, 79, 7);
				}
				if (ArmorHideAndShowProcedure.execute(entity))
					Minecraft.getInstance().font.draw(event.getMatrixStack(), "" + (entity.getPersistentData().getString("ArmorNumShow")) + "",
							posX - 65 , h - 48, -16777216);
				RenderSystem.setShaderTexture(0, new ResourceLocation("playerhuds:textures/hud_strip_bg.png"));
				Minecraft.getInstance().gui.blit(event.getMatrixStack(), posX + 10, h - 39, 0, 0, 81, 9, 81, 9);

				RenderSystem.setShaderTexture(0, new ResourceLocation("playerhuds:textures/hunger_strip.png"));
				Minecraft.getInstance().gui.blit(event.getMatrixStack(), posX + 11 + (int)(entity.getPersistentData().getDouble("HungerStripMoveUpdate")) , h - 38, 0, 0, (int)(entity.getPersistentData().getDouble("HungerStripUpdate")), 7, 79, 7);

				Minecraft.getInstance().font.draw(event.getMatrixStack(), "" + (entity.getPersistentData().getString("HungerNumShow")) + "",
						posX + 37, h - 38, -1);
				if (AirHideAndShowProcedure.execute(entity)) {
					RenderSystem.setShaderTexture(0, new ResourceLocation("playerhuds:textures/hud_strip_bg.png"));
					Minecraft.getInstance().gui.blit(event.getMatrixStack(), posX + 10, h - 49, 0, 0, 81, 9, 81, 9);
				}
				if (AirHideAndShowProcedure.execute(entity)) {
					RenderSystem.setShaderTexture(0, new ResourceLocation("playerhuds:textures/breath_strip.png"));
					Minecraft.getInstance().gui.blit(event.getMatrixStack(), posX + 11 + (int)(entity.getPersistentData().getDouble("AirStripMoveUpdate")), h - 48, 0, 0, (int)(entity.getPersistentData().getDouble("AirStripUpdate")), 7, 79, 7);
				}
				if (AirHideAndShowProcedure.execute(entity))
					Minecraft.getInstance().font.draw(event.getMatrixStack(), "" + (entity.getPersistentData().getString("AirNumShow")) + "",
							posX + 37, h - 48, -16777216);
			}
			RenderSystem.depthMask(true);
			RenderSystem.defaultBlendFunc();
			RenderSystem.enableDepthTest();
			RenderSystem.disableBlend();
			RenderSystem.setShaderColor(1, 1, 1, 1);
		}
	}
}
